#ifndef __STMFLASH_H
#define __STMFLASH_H
#include "simplelib_cfg.h"
#ifdef SLIB_USE_FLASH

#include "main.h"
#include "flash.h"
#define FLASH_WAITETIME  50000          //FLASH等待超时时间

#ifdef STM32F407xx
#include "stm32f4xx_hal.h"
#include "stm32f4xx_hal_flash.h"
#include "usart.h"
//本程序只供学习使用，未经作者许可，不得用于其它任何用途
//ALIENTEK STM32F429开发板
//STM32内部FLASH读写 驱动代码	   
//正点原子@ALIENTEK
//技术论坛:www.openedv.com
//创建日期:2016/1/16
//版本：V1.0
//版权所有，盗版必究。
//Copyright(C) 广州市星翼电子科技有限公司 2014-2024
//All rights reserved									  
////////////////////////////////////////////////////////////////////////////////// 	

//FLASH起始地址
#define STM32_FLASH_BASE 0x08000000 	//STM32 FLASH的起始地址
#define FLASH_SAVE_ADDR  0X080A0000     //设置FLASH 保存地址(必须为4的倍数，且所在扇区,要大于本代码所占用到的扇区.

extern float flash_chassis_init_x, flash_chassis_init_y;

//FLASH 扇区的起始地址
#define ADDR_FLASH_SECTOR_0     ((u32)0x08000000) 	//扇区0起始地址, 16 Kbytes  
#define ADDR_FLASH_SECTOR_1     ((u32)0x08004000) 	//扇区1起始地址, 16 Kbytes  
#define ADDR_FLASH_SECTOR_2     ((u32)0x08008000) 	//扇区2起始地址, 16 Kbytes  
#define ADDR_FLASH_SECTOR_3     ((u32)0x0800C000) 	//扇区3起始地址, 16 Kbytes  
#define ADDR_FLASH_SECTOR_4     ((u32)0x08010000) 	//扇区4起始地址, 64 Kbytes  
#define ADDR_FLASH_SECTOR_5     ((u32)0x08020000) 	//扇区5起始地址, 128 Kbytes  
#define ADDR_FLASH_SECTOR_6     ((u32)0x08040000) 	//扇区6起始地址, 128 Kbytes  
#define ADDR_FLASH_SECTOR_7     ((u32)0x08060000) 	//扇区7起始地址, 128 Kbytes  
#define ADDR_FLASH_SECTOR_8     ((u32)0x08080000) 	//扇区8起始地址, 128 Kbytes  
#define ADDR_FLASH_SECTOR_9     ((u32)0x080A0000) 	//扇区9起始地址, 128 Kbytes  
#define ADDR_FLASH_SECTOR_10    ((u32)0x080C0000) 	//扇区10起始地址,128 Kbytes  
#define ADDR_FLASH_SECTOR_11    ((u32)0x080E0000) 	//扇区11起始地址,128 Kbytes 

void STMFLASH_Write(u32 WriteAddr,u32 *pBuffer,u32 NumToWrite);		//从指定地址开始写入指定长度的数据
void STMFLASH_Read(u32 ReadAddr,u32 *pBuffer,u32 NumToRead);   		//从指定地址开始读出指定长度的数据

//测试写入
void Test_Write(u32 WriteAddr,u32 WriteData);	
#endif // STM32F407xx

#ifdef STM32F072xB

#include "stm32f0xx_hal.h"
#include "stm32f0xx_hal_flash.h"
#define STM32_FLASH_BASE					0x08000000 // STM32F07xB FLASH 地址
#define FLASH_SAVE_ADDR                     0x08010000 // FLASH 内容保存

// TODO: Simon	due:NONE	Finish sector addr 0~63 sector may no finish anyway.
#define ADDR_FLASH_SECTOR_0					((u32)0x08000000) // Sector 0, 4KB


#endif // STM32F072xB 
extern float flash_data[FLASH_SIZE];
 
void write_prams();
void load_prams();
#endif // SLIB_USE_FLASH
#endif
